<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var decodeString = function (s) {
      let reg = /(\d+)\[([a-zA-Z]+)\]/g;
      while (s.indexOf('[') > 0) {
        s = s.replace(reg, (_, ...[num, str]) => {
          let result = "";
          for (let i = 0; i < num - 0; i++) {
            result += str;
          }
          return result;
        });
      }
      return s;
    };
    console.log(decodeString("3[a]2[bc]"));
  </script>
</body>

</html>